package cn.sccl.common.scaffold.filegens;


import cn.sccl.common.scaffold.FileConfig;
import cn.sccl.common.scaffold.FileGenerator;

import java.util.HashMap;
import java.util.Map;

/**
 * 模型类的文件生成器
 * Created by 杨浩宇 on 2016-02-20.
 */
public class ModelFileGenerator extends FileGenerator {

    @Override
    public String getTemplate() {
        return "model.ftl";
    }

    @Override
    public boolean storeToJavaSrc() {
        return true;
    }

    @Override
    public String getTargetPath(String projectPath, String packagePath, String modelName) {
        return projectPath + "/" + packagePath + "/model/" + modelName + ".java";
    }

    @Override
    public Map fillParams(FileConfig f) {
        Map map = new HashMap();
        map.put("package", f.getBasePackage() + ".model");
        map.put("model", f.getModelName());
        map.put("tableName", f.getTableInfo().getTableName());
        map.put("tableComments", f.getTableInfo().getTableComments());

//        List<ModelProperty> properties = new ArrayList<ModelProperty>();
//        for (ColumnInfo columnInfo : f.getTableInfo().getColumnInfos()) {//列信息转换为模型类的属性。
//            ModelProperty p = new ModelProperty(columnInfo.toJavaType().getName(), StrUtils.toCamelCase(columnInfo.getColumnName().toLowerCase()), columnInfo.getComments() , columnInfo.getColumnName() , columnInfo.getJdbcType());
//            properties.add(p);
//        }
        map.put("properties", f.getTableInfo().getColumnInfos());
        return map;
    }


}
